package com.gitee.wsl.common.svg.gradient

import androidx.annotation.FloatRange
import androidx.annotation.IntRange
import com.gitee.wsl.common.svg.attributes.AttributeProperty
import com.gitee.wsl.common.svg.attributes.AttributeType
import com.gitee.wsl.common.svg.attributes.DefaultAttributeProperty
import com.gitee.wsl.common.svg.attributes.FloatAttributeProperty
import com.gitee.wsl.common.svg.attributes.IntAttributeProperty
import com.gitee.wsl.common.svg.elements.Element
import com.gitee.wsl.common.svg.clip.PosMode


open class BaseGradient(name:String, validation: Boolean = false) : Element(name, validation) {

    /**
     * Coordinate mode
     *
     * @see PosMode
     */
    var posMode : PosMode? by DefaultAttributeProperty()

    /**
     * Repeat method
     * [SpreadMode.SPREAD_PAD] not repeat,it will use end color fill other
     * [SpreadMode.SPREAD_REFLECT] it will reverse fill and repeat
     * [SpreadMode.SPREAD_REPEAT] it will repeat fill
     */
    var spreadMode : SpreadMode? by DefaultAttributeProperty()

    /**
     * The offset color
     */
   val stopColorList = mutableListOf<StopColorItem>()

   fun stopColor(block:StopColorItem.()->Unit): StopColorItem{
       val item = add(StopColorItem(validation), block)
       stopColorList.add(item)
       return item
   }


   class StopColorItem(validation: Boolean = false): Element("stop", validation) {
       /**
        * 0.0-1.0
        */
       private var _offset : Float? by FloatAttributeProperty("offset",type = AttributeType.Length)

       @FloatRange(0.0,1.0)
       var offset : Float? = null
           get() = _offset
           set(value) {
               field = value
               _offset = value
           }

       var color : String? by AttributeProperty("stop-color")

       /**
        * 0-255
        */
       private var _opacity : Int? by IntAttributeProperty("stop-opacity",type = AttributeType.Length)

       @IntRange(0,255)
       var opacity : Int? = null
           get() = _opacity
           set(value) {
               field = value
               _opacity = value
           }
   }
}

enum class SpreadMode(val value:String) {

    SPREAD_PAD ( "pad"),SPREAD_REPEAT("repeat"),SPREAD_REFLECT("reflect");

    override fun toString(): String {
        return value
    }

}
